package controllers;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import model.Room;
import model.RoomHasBooking;
import util.DBController;
import dao.impl.RoomDaoImpl;
import dao.impl.AvailableRoomDaoImpl;
import dao.impl.RoomTypeDaoImpl;

import dao.intf.RoomDao;
import dao.intf.AvailableRoomDao;
//import com.google.gson.*;
import model.AvailableRoom;

/**
 * Servlet implementation class Availability
 */
@WebServlet("/Availability")
public class AvailabilityServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AvailabilityServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub 
		// set parameter
		String start = request.getParameter("checkindate");
		String end = request.getParameter("checkoutdate");
		String roomType = request.getParameter("roomtype");
		String adult = request.getParameter("adult");
		String children = request.getParameter("children");
		String noOfRooms = request.getParameter("rooms");
		String night = request.getParameter("night");	
		String bookingid = request.getParameter("bookingid");	
		String bookingemail = request.getParameter("bookingemail");	
		
		//		
		/*PrintWriter out = response.getWriter();		
		response.setContentType("text/HTML");
		out.println("Avail Servlet - " + start + "," + end + "," + roomType + "," + adult + "," + children + "," + noOfRooms + "," + night);
		*/
		List<AvailableRoom> AvailroomList = new ArrayList<AvailableRoom>();														
		AvailableRoomDaoImpl AvailableroomDaoObj = new dao.impl.AvailableRoomDaoImpl();	
		
		AvailroomList = AvailableroomDaoObj.getAvailableRoomList(start, end, roomType, adult, children, noOfRooms  , night);
		AvailroomList.get(0).setBookingId(bookingid);
		AvailroomList.get(0).setBookingEmail(bookingemail);
		
		request.setAttribute("roomlist", AvailroomList);
		RequestDispatcher dispatcher = request.getRequestDispatcher("/availability.jsp");
		dispatcher.forward(request,response);	
		
		
	}
	public String GetResult(){
			
		String result = "<Students>";
		result += "<Student><Name>May</Name>";
		result += "<Hostel>Hostel</Hostel>";
		result += "<Contact>Contact</Contact>";
		result += "</Student>A</Students>";
		return result;
	}
}
